package flc.ast.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import flc.ast.R;
import flc.ast.activity.DomainActivity;
import flc.ast.activity.PortScanActivity;
import flc.ast.activity.TraceActivity;
import flc.ast.databinding.FragmentDebugBinding;
import flc.ast.dialog.DeleteDialog;
import flc.ast.dialog.DnsDialog;
import flc.ast.dialog.DnsTipDialog;
import flc.ast.dialog.IpQueryDialog;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link DebugFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class DebugFragment extends BaseNoModelFragment<FragmentDebugBinding> {


    @Override
    protected int onCreate() {
        return R.layout.fragment_debug;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);

        mDataBinding.flTrace.setOnClickListener(this);
        mDataBinding.flDns.setOnClickListener(this);
        mDataBinding.flPortScan.setOnClickListener(this);
        mDataBinding.flIpQuery.setOnClickListener(this);
        mDataBinding.llDomain.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.flTrace://Trace查询
                startActivity(TraceActivity.class);
                break;
            case R.id.flDns://dns查询
                showDnsTipDialog();
                break;
            case R.id.flPortScan://端口扫描
                startActivity(PortScanActivity.class);
                break;
            case R.id.flIpQuery://ip查询
                showIpQueryDialog();
                break;
            case R.id.llDomain://域名解析
                startActivity(DomainActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {

    }

    private void showDnsTipDialog() {
        DnsTipDialog dialog = new DnsTipDialog(mContext);
        dialog.setListener(new DnsTipDialog.Ilistener() {

            @Override
            public void click() {
                showDnsDialog();
            }

        });
        dialog.show();
    }

    private void showDnsDialog() {
        DnsDialog dialog = new DnsDialog(mContext);
        dialog.show();
    }

    private void showIpQueryDialog() {
        IpQueryDialog dialog = new IpQueryDialog(mContext);
        dialog.show();
    }

}